﻿using YunFeng.TypeCreator.Models;
using YunFeng.TypeCreator;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {

            //var expect = new TypeExpectation
            //{
            //    ClassName = "DynamicClass",
            //    Properties = new List<PropertyDescription>
            //{
            //    new PropertyDescription
            //    {
            //        PropertyName="Name",
            //        PropertyType=typeof(string),
            //        PropertyValue="小明",
            //        Attributes=new List<AttributeOnProperty>
            //        {
            //            //new AttributeOnProperty
            //            //{
            //            //    AttributeType = typeof(RequiredAttribute),
            //            //    AttributeConstructorType =new Type[]{ } ,
            //            //    AttributeConstructorTypeParam =new object[] { }
            //            //},
            //        }
            //    },
            //     new PropertyDescription
            //    {
            //        PropertyName="Age",
            //        PropertyType=typeof(int),
            //        PropertyValue=18,
            //        Attributes=new List<AttributeOnProperty>
            //        {
            //            //new AttributeOnProperty
            //            //{
            //            //    AttributeType = typeof(RangeAttribute),
            //            //    AttributeConstructorType =new Type[]{ typeof(int),typeof(int) } ,
            //            //    AttributeConstructorTypeParam =new object[] { 0,100}
            //            //},
            //        }
            //    }
            //}
            //};
            //TypeCreator typeCreator = new TypeCreator();
            //var expectObj = typeCreator.CreateExpectationObject(expect, out Type type);

            TypeCreatorBuilder builder = new TypeCreatorBuilder();
            var expectObj = builder.SetClassName("Student")
                  .WithProperty("Name", typeof(string), "小明")
                  .HasAttribute(typeof(RequiredAttribute), Array.Empty<Type>(), Array.Empty<object>())
                  .WithProperty("Age", typeof(int), 18)
                  .HasAttribute(typeof(RequiredAttribute), Array.Empty<Type>(), Array.Empty<object>())
                  .HasAttribute(typeof(RangeAttribute), [typeof(int), typeof(int)], [0, 100])
                  .CreateOjbect();

            var exampleObje = new TypeCreatorBuilder()
                .SetClassName("Rectangular")
                .WithProperty("Width", typeof(int), 300)
                .WithProperty("Heigh", typeof(int), 300)
                .CreateOjbect();

            Console.WriteLine(expectObj.GetType());
            foreach (var item in expectObj.GetType().GetProperties())
            {
                Console.WriteLine($"[Type]:{item.GetType()} [propertyName]:{item.Name}\t [propertyValue]:{item.GetValue(expectObj)}");
                var attributes = item.GetCustomAttributes(true);
                foreach (var attribute in attributes)
                {
                    foreach (var aprop in attribute.GetType().GetProperties())
                    {
                        Console.WriteLine($"[attribute Type]:{attribute.GetType()} [attribute propertyName]:{aprop.Name}\t [attribute propertyValue]:{aprop.GetValue(attribute)}");
                    }
                }
            }


            Console.ReadKey();
        }
    }


    public class RequiredAttribute : Attribute
    {

    }

    public class RangeAttribute : Attribute
    {
        public int Min { get; set; }
        public int Max { get; set; }
        public RangeAttribute(int min, int max)
        {
            Min = min;
            Max = max;
        }
    }
}
